<template>
	<view class="DiscoverItem">
		<view class="item-title" v-if="title">{{title}}</view>
		<view v-if="list">
			<view class="list-img" v-for="(item,index) in list" :key="index" @click="jumpDetails(item.postid)">
				<image style="width: 100vw; height: 210px;display: block;"  mode="widthFix" @error="imageError" :src="item.image"></image>
				<view class="image-info">
					<view class="image-dur" v-if="item.cates">
						<text>{{item.cates[0].catename+" / "}}</text>
						<text>{{duration(item.duration)}}</text>
					</view>
					<view class="image-text">{{item.title}}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "DiscoverItem",
		props: {
			list: Array,
			title: String,
		},
		methods: {
			duration(n) {
				n = parseInt(n);
				let m = parseInt(Math.floor(n / 60));
				if (m < 10) {
					m = "0" + m;
				}
				let s = n % 60;
				if (s < 10) {
					s = "0" + s;
				}
				return m + "'" + s + "\"";
			},
			jumpDetails(id){
				uni.showLoading({
					title:'加载中'
				});
				uni.request({
					url:`https://apis.netstart.cn/vmovier/post/view?postid=${id}`,
					success: (res) => {
						this.$store.commit('updateDetails', {
							details: res.data.data,
						});
						uni.navigateTo({
							url: `../../pages/details/details?postid=${id}`,
							complete: () => {
								uni.hideLoading();
							}
						})
					}
					
				})
			}
		}

	}
</script>

<style lang="less">
	.DiscoverItem {
		.item-title {
			background-color: black;
			color: white;
			text-align: center;
			line-height: 100rpx;
		}
		.list-img{
			position: relative;
			.image-info{
				position: absolute;
				bottom: 3vw;
				left: 3vw;
				.image-dur{
					color: #ece6df;
					font-size: 12px;
				}
				.image-text{
					color: white;
					font-size:30rpx;
					font-weight: bold;
				}
			}
		}
	}
</style>
